<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .red {
            color: #f00;
        }

        .blue {
            color: #0ff;
        }
    </style>
</head>

<body>
    <main id="app">
        <p :class="classObject">我是p标签</p>
        <p :class="classArray">我是p标签</p>
        <button v-on:click="handleClick">点击</button>
    </main>
</body>
<script src="../vue.min.js"></script>
<script>
    let vue = new Vue({
        el: "#app",
        data() {
            return {
                colorFlag: true,
            }
        },
        computed: {
            classObject() {
                return {
                    red: !this.colorFlag,
                    blue: this.colorFlag
                }      
            },
            classArray() {
                return [
                    this.colorFlag ? 'red' : '',
                    this.colorFlag ? '' : 'blue'
                ];
            }
        },
        methods: {
            handleClick() {
                this.colorFlag = !this.colorFlag;
            }
        }
    })
</script>

</html>